package com.topideal.supplychain.hades.master.mapper;

import com.topideal.supplychain.hades.master.model.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 用户
 *
 * @author xuxiaoyan
 * @date 2018-09-19 16:56
 */
@Mapper
public interface UserMapper {

    /**
     * 根据userkey或中文名/英文名搜索
     *
     * @param query
     * @return
     */
    @Select("<script> " +
            "select cu.display_name as displayName, au.user_key as userKey, au.lower_user_name as lowerUserName "
            + "from app_user au "
            + "inner join cwd_user cu on au.lower_user_name = cu.lower_user_name "
            + "inner join cwd_directory dir on dir.id = cu.directory_id "
            + "<where>"
            + " <if test=\"query != null and query != '' \"> "
            + "and ( cu.display_name like concat('%',#{query},'%') or au.user_key like concat('%',#{query},'%') or au.lower_user_name like concat('%',#{query},'%'))</if> "
            + " </where> "
            + " </script> ")
    List<User> selectByQuery(@Param("query") String query);
}
